using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;


public class PlayerView : MonoBehaviour
{
    [Header("血量图标")]
    [SerializeField] private GameObject[] playerBloodIcon = new GameObject[4];

    [Header("UI")]
    [SerializeField] private GameObject playerBloodUI;
    [SerializeField] private TMP_Text playerScoreText;
    
    
    // 更新UI视图
    public void UpdateViewInfo(PlayerModel data)
    {
        playerScoreText.text = data.GetPlayerScore.ToString();
        Debug.Log("更新数据 视图数据更新");
        
        // 移除所有图标
        RemoveBloodIcon();
        // 挂载血量图标
        for (int i = 0; i < data.GetPlayerBlood; i++)
        {
            // 把栈中的数据依次挂载到UI组件上
            AddBloodIcon(playerBloodIcon[i]);
        }
    }
    
    // 添加图标
    private void AddBloodIcon(GameObject playerBloodIcon)
    {
        AddPrefabToGameObject.Instance.AddPrefab(playerBloodIcon, playerBloodUI);
    }
    
    // 移除图标
    private void RemoveBloodIcon()
    {
        // 移除一个血量图标
        // AddPrefabToGameObject.Instance.RemoveChildObject(playerBloodUISta.Pop(), playerBloodUI);
        // 移除所有子物体
        AddPrefabToGameObject.Instance.RemoveAllChildObjects(playerBloodUI);
    }
}